class MusicPlayer {
  private var playlist: Vector[String] = Vector.empty
  private var currentIndex: Int = -1
  private var playMode: String = "sequential"

  def addMusic(song: String): Unit = playlist = playlist :+ song

  def removeMusic(song: String): Unit = playlist = playlist.filterNot(_ == song)

  def setPlayMode(mode: String): Unit = playMode = mode

  def play(): Unit = {
    if (playlist.isEmpty) println("Playlist is empty")
    else {
      currentIndex = if (currentIndex == -1) 0 else getNextIndex
      println(s"Playing: ${playlist(currentIndex)}")
    }
  }

  private def getNextIndex: Int = playMode match {
    case "loop"    => (currentIndex + 1) % playlist.length
    case "shuffle" => scala.util.Random.nextInt(playlist.length)
    case _ => if (currentIndex + 1 >= playlist.length) -1 else currentIndex + 1
  }

  def next(): Unit = {
    currentIndex = getNextIndex
    if (currentIndex == -1) println("Reached end of playlist")
    else println(s"Playing: ${playlist(currentIndex)}")
  }
}
